package com.wei.czz.framework.game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wei.czz.framework.game.dao.GameUserFlowDao;
import com.wei.czz.framework.game.entity.GameUserFlowEntity;
import com.wei.czz.framework.game.service.GameUserFlowService;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2023-03-16 11:37:17
 * className: GameUserFlowServiceImpl 游戏用户变更流水请求服务接口实现类
 * version: 1.0
 * description:
 */
@Service("gameUserFlowService")
public class GameUserFlowServiceImpl extends ServiceImpl<GameUserFlowDao, GameUserFlowEntity> implements GameUserFlowService {

    private static final Logger log = LoggerFactory.getLogger(GameUserFlowServiceImpl.class);

    @Override
    public void saveGameUserFlow(Long userId, Long gameId, String title, String content, Long createUser) {

        GameUserFlowEntity gameUserFlow = new GameUserFlowEntity();
        // 属性赋值
        gameUserFlow.setUserId(userId)
                .setGameId(gameId)
                .setTitle(title)
                .setContent(content)
                .setCreateTime(new Date())
                .setCreateUser(createUser);
        // 插入数据
        baseMapper.insert(gameUserFlow);
        log.info("游戏用户流水数据插入完成");

    }

    @Override
    public void saveGameUserFlow(List<Long> userIdList, Long gameId, String title, String content, Long createUser) {
        List<GameUserFlowEntity> gameUserFlowList = new ArrayList<>(userIdList.size());
        Date date = new Date();
        for (Long userId : userIdList) {
            GameUserFlowEntity gameUserFlow = new GameUserFlowEntity();
            // 属性赋值
            gameUserFlow.setUserId(userId)
                    .setGameId(gameId)
                    .setTitle(title)
                    .setContent(content)
                    .setCreateTime(date)
                    .setCreateUser(createUser);
            gameUserFlowList.add(gameUserFlow);
        }
        // 插入数据
        boolean bool = this.saveBatch(gameUserFlowList);
        log.info("游戏用户流水数据批量插入完成。bool={}", bool);
    }

    @Override
    public List<GameUserFlowEntity> getGameUserFlowList(Long userId, Long gameId) {
        LambdaQueryWrapper<GameUserFlowEntity> gameUserFlowLambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 匹配条件
        gameUserFlowLambdaQueryWrapper.eq(GameUserFlowEntity::getUserId, userId)
                .eq(GameUserFlowEntity::getGameId, gameId);
        // 查询数据
        List<GameUserFlowEntity> gameUserFlowList = baseMapper.selectList(gameUserFlowLambdaQueryWrapper);
        if (gameUserFlowList.isEmpty()) {
            log.info("查询游戏用户流水结果为空。userId={} gameId={}", userId, gameId);
        }
        return gameUserFlowList;
    }
}